#pragma once

#include "../Model.h"
#include "../../spline.h"

namespace Tmpl {

struct TreeBranchSettings
{
	// default settings
	TreeBranchSettings()
	{
		axisLength = 25.0f;
		axisVariation = 0.2f;
		axisResolution = 10;
		axisBending = 0.25f;
		axisLightInfluence.SetType(Spline2f::SPLINE_BEZIER_QUAD);
		axisLightInfluence.AddPoint(Vec2f(0.0f, 0.25f));
		axisLightInfluence.AddPoint(Vec2f(1.0f, 0.25f));

		renderRadius = 1.0f;
		renderProfile.SetType(Spline2f::SPLINE_BEZIER_QUAD);
		renderProfile.AddPoint(Vec2f(0.0f, 1.0f));
		renderProfile.AddPoint(Vec2f(1.0f, 0.0f));
		renderResolution = 12;
		renderSegments = 6;

		branchingOffsetInfluence.SetType(Spline2f::SPLINE_BEZIER_QUAD);
		branchingOffsetInfluence.AddPoint(Vec2f(0.0f, 0.75f));
		branchingOffsetInfluence.AddPoint(Vec2f(1.0f, 0.25f));
		branchingInheritRadius = true;
		branchingOffsetMin = 0.2f;
		branchingOffsetMax = 1.0f;
		branchingBranches = 5;
		branchingAxisVariation = 0.0f;

		leafSize = Vec2f(0.25f, 0.25f);
	}

	// axis
	float axisLength;
	float axisVariation;
	int axisResolution;
	float axisBending;
	Spline2f axisLightInfluence;

	// render
	float renderRadius;
	Spline2f  renderProfile;
	int renderResolution;
	int renderSegments;

	// branching
	Spline2f branchingOffsetInfluence;
	bool branchingInheritRadius;
	float branchingOffsetMin;
	float branchingOffsetMax;
	int branchingBranches;
	float branchingAxisVariation;

	// material



	// leaves
	Vec2f leafSize;

	// childs
	std::vector<TreeBranchSettings> childs;
};

struct TreeSettings
{
	int seed;
	TreeBranchSettings trunk;
};

class Tree
{
public:
	Tree(const TreeSettings& settings);
	~Tree();

	int GetTriangleCount(){return ((mStems)?mStems->GetTriangleCount():0) + ((mLeaves)?mLeaves->GetTriangleCount():0);}

	void Render(const Matrix4x4f& projection, const Matrix4x4f* modelView, int count);
private:
	TreeSettings mSettings;

	GLuint mTexId;

	Model* mStems;
	Model* mLeaves;
};

}; // namespace Tmpl